<template>
  <div>
    <el-dialog
      title="详细信息"
      :visible.sync="dialogVisible"
      width="600px"
      destroy-on-close
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="名称" prop="name">
              <el-input v-model="form.name" placeholder="" maxlength="30" />
            </el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item label="code" prop="code">
              <el-input v-model="form.code" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="分类" prop="cate">
              <el-input v-model="form.cate" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="学分" prop="classhour">
              <el-input v-model="form.classhour" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="备注">
              <el-input v-model="form.snote" type="textarea"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="dialogVisible = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { courseService } from "@/api/dormService";

export default {
  dicts: [],
  components: {},

  data() {
    return {
      resolve: null,
      dialogVisible: false,

      // 表单参数
      form: {
        id: "",
        name: undefined,
        code: undefined,
        snote: undefined,
        classhour: undefined,
        cate: "",
      },

      // 表单校验
      rules: {
        name: [
          { required: true, message: "不能为空", trigger: "blur" },
          {
            min: 2,
            max: 100,
            message: "用户名称长度必须介于 2 和 100 之间",
            trigger: "blur",
          },
        ],
        // code: [{ required: true, message: "不能为空", trigger: "blur" }],
      },
    };
  },
  methods: {
    open(row) {
      console.log(row);
      this.dialogVisible = true;
      this.form = {
        id: "",
        name: undefined,
        code: undefined,
        snote: undefined,
      };
      row && (this.form = row);
      return new Promise((resolve) => {
        this.resolve = resolve;
      });
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          courseService.postSave(this.form).then((response) => {
            this.$modal.msgSuccess("操作成功");
            this.dialogVisible = false;
            // this.getList();
            this.resolve(response.data);
          });
        }
      });
    },

    // 取消按钮
    cancel() {
      this.dialogVisible = false;
      // this.reset();
    },
  },
};
</script>

<style lang="scss" scoped></style>
